// *******************************************************************************************************
// # ショップ
//   ・トップ
// *******************************************************************************************************
$(function(){
	var isUnderIe6 = uaInfo.isIe && uaInfo.ieVr <= 6,
		isUnderIe7 = uaInfo.isIe && uaInfo.ieVr <= 7;

	/*******************************************************
	 *　モーダルマップ
	 *******************************************************/
	var modalMap = new APMN.Modal({
		target: $('#modal_map'),
		close: $('#modal_map .modal_close'),
		ieVr: !(isUnderIe6)
		});

	/*modalMap実行*/
	$('.open_modal_map a').on('click' , function(e){
		e.preventDefault();
		modalMap.show();
	});
	
	/*******************************************************
	 *　tooltip
	 *******************************************************/
	function tooltips(){
		$('.tooltip').powerTip({
			placement: isUnderIe6 ? 'e' : 'n'
		});
		$('.tooltip.zoom').each(function(i){
			$(this).data('powertiptarget', $(this).next().attr('id'));
		});
	};

	/*******************************************************
	    *　heightLine
	    *******************************************************/ 
	function heightline(){
		$('.article_list ul li .head').heightLine();
		$('.article_list ul li .inner').heightLine();
		$('.article_list ul li .feature').heightLine();

		//$('.staff .mod_box_section ul li').heightLine();
		onControlSetHeightLine();
	};

	//staff-arae timing control
	function onControlSetHeightLine(){
		setTimeout(function(){setHightLine()},2000);
		
		function setHightLine(){
			$('.staff .mod_box_section ul li').heightLine();
		}
	};

	function setTimeControlHeightLine(ary){
		setTimeout(function(){setHeightLineEvent()},2000);

		function setHeightLineEvent(){
			$.each(ary, function(i, value) {
				$(value).heightLine();
			});
		}
	}

	/*******************************************************
	 * map
	 *******************************************************/
	var $mapOpnBtn = $('.around_map .open_menu'),
		$mapOpnTrg = $('.around_map .map');
	var mapOpener = new APMN.ToggleOpener({
		btn: $mapOpnBtn,
		target: $mapOpnTrg,
		isOpen: $('.around_map .open_menu').hasClass('active')
	});
	mapOpener.toggle = function(b) {
		if (b) $mapOpnBtn.addClass('active');
		else $mapOpnBtn.removeClass('active');
	};

	function makeMap() {
		var x = parseFloat($('.map').attr('lat'))/1000;
		var y = parseFloat($('.map').attr('lon'))/1000;
		var scl = 400;

		var map = new Mapple.SingleMap("map", 880, 400, x, y, scl, {
			k1: "apanew",
			k2: "1205jdwa", 
			scaleOperateVisible: false ,scaleOperate: false,rotateOperateVisible: false
		});

		var iconLayer = map.createOverlayIcons();
		iconLayer.append("icon0", x, y, {
			name: $(".mod_ttl_page").text(),
			normalSrc: "/static/shared/images/icon/map/icon_shop.png",
			clickMove: true,
			cursor: "pointer",
			scaleLevel: null,
			state: 'normal',
			normal: {
				leftOffset: -20,
				leftOffsetUnit: 'pixels',
				topOffset: 60,
				topOffsetUnit: 'pixels',
				scale: 1.0
			}
		});
	};

    makeMap();

	/*******************************************************
	 *@articlelist
	 *******************************************************/
	function articlelist(){
		$('.article_list li').each(function(i){
			var $box  = $(this).find('.mod_box_section'),
				$over = $box.find('.over');

			$over.find('span').css({
				marginTop: -$over.find('span').outerHeight()*0.5,
			});

			$box.hover(function(e){
				$over.show();
			}, function(e){
				$over.hide();
			});
			$over.hide();
		});
	};

	$(".mod_btn_all_pink").click(function() {
		var items = [];
		items.push({name:'search_type',value:'shop'});
		items.push({name:'shopCd',value:$(this).attr("id")}); 
		items.push({name:'page',value:'1'});
		submit('/rstobi/rstobi','POST',items);
	});
	
	// init
	tooltips();
	heightline();
	//mapArea();
	articlelist();
	
/*	setTimeControlHeightLine([
		'.article_list ul li .head',
		'.article_list ul li .inner',
		'.article_list ul li .feature',
		'.staff .mod_box_section ul li'
	]);*/
});

/*
 * 
 */

function showAllTatemono(shopCd)
{
	var items = [];
	items.push({name:'search_type',value:'shop'});
	items.push({name:'shopCd',value:shopCd}); 
	items.push({name:'page',value:'1'});
	submit('/rstobi/rstobi','POST',items);
}

/*
 * Submit
 */
function submit(action, method, values) {
    var form = $('<form/>', {
        action: action,
        method: method
    });
    $.each(values, function() {
        form.append($('<input/>', {
            type: 'hidden',
            name: this.name,
            value: this.value
        }));    
    });
    form.appendTo('body').submit();
}
